import javax.management.ListenerNotFoundException;
import javax.swing.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-01-10
 * Time: 13:31
 */
public class MyLinkQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;
    public int usedSize;
    public void offer(int val){
        ListNode node =new ListNode(val );
        if(head==null){
            head=node;
            last=node;

        }else {
            last.next = node;
            node.prev = last;
            last = node;
        }
        usedSize++;

    }
    public int poll(){
        if(empty()){
            throw new NullException("队列为空");

        }
        int m=head.val;
        usedSize--;
        if(head.next==null){
            head=null;
            last=null;
            return m;
        }

        head=head.next;
        head.prev=null;

        return m;

    }
public boolean empty(){
        return head==null;
}

    public int peek(){
            if(empty()){
                throw new NullException("队列为空");
            }
            return head.val;

        }
    public int size(){
        return usedSize;
    }



}
